﻿Imports BUS
Imports DAO
Imports DTO
Imports System.Linq

Public Class DangNhap

    Private Sub DanhNhap_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txt_pw.PasswordChar = "*"
        txt_pw.MaxLength = 10
    End Sub

    Public Sub CheckLogin(ByVal style As Integer)
        Dim usBus As UserBUS = New UserBUS()
        Dim us As String = txt_user.Text
        Dim mk As String = txt_pw.Text

        Dim result As Integer = usBus.getUser_BUS(us, mk, style)

        If result = 1 Then
            If style = 1 Then
                Me.Hide()
                Dim frm As QLHS = New QLHS()
                frm.Show()
            ElseIf style = 2 Then
                Me.Hide()
                Dim frm As QLHS = New QLHS()
                frm.Show()
            Else
                Me.Hide()
                Dim frm As QLPH_HS = New QLPH_HS()
                frm.Show()
            End If

        Else
            lbl_user.Text = "Vui lòng kiểm tra lại tên đăng nhập"
            txt_user.Focus()
            lbl_pw.Text = "Vui lòng kiểm tra lại mật khẩu"
            txt_pw.Focus()
        End If
    End Sub

    Private Sub btn_dangnhap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_dangnhap.Click
       If rd_1.Checked = True Then
            Dim style As Integer = 1
            CheckLogin(style)

        ElseIf rd_2.Checked = True Then
            Dim style As Integer = 2
            CheckLogin(style)

        ElseIf rd_3.Checked = True Then
            Dim style As Integer = 3
            CheckLogin(style)
        End If

    End Sub

    Private Sub btn_Thoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Thoat.Click
        'Me.Close()
        Application.Exit()
    End Sub

    Private Sub txt_user_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt_user.KeyDown
        lbl_error.Text = ""
        lbl_user.Text = ""
        txt_pw.Text = ""
    End Sub

    Private Sub txt_mk_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txt_pw.KeyDown
        lbl_pw.Text = ""
    End Sub

    Private Sub txt_user_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_user.Leave
        If txt_user.Text = "" Then
            lbl_user.Text = "Tên đăng nhập không được trống"
            txt_user.Focus()
        End If
    End Sub

    Private Sub txt_pw_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_pw.Leave
        If txt_pw.Text = "" Then
            lbl_pw.Text = "Mật khẩu không được trống"
            txt_pw.Focus()
        End If
    End Sub

    Private Sub rd_2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rd_2.CheckedChanged
        txt_user.Text = "giaovu"
        txt_pw.Text = "123456"
    End Sub

    Private Sub rd_3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rd_3.CheckedChanged
        txt_user.Text = "phuhuynh"
        txt_pw.Text = "123456"
    End Sub

    Private Sub rd_1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rd_1.CheckedChanged
        txt_user.Text = "admin"
        txt_pw.Text = "123456"
    End Sub
End Class